package cn.com.dycc.meeting_assist.meeting_info.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.meeting_assist.meeting_info.entity.MeetingInfo;
import cn.com.dycc.meeting_assist.meeting_info.param.FindMeetingInfoParam;
import cn.com.dycc.meeting_assist.meeting_info.param.MeetingInfoParam;
import cn.com.dycc.meeting_assist.meeting_info.service.MeetingInfoNotFoundException;
import cn.com.dycc.meeting_assist.meeting_info.service.MeetingInfoService;
import cn.com.dycc.util.JsonObjectResult;


/**
 * 
 * Description: 会议信息管理控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年10月26日 下午3:54:20.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/meetingInfo")
public class MeetingInfoController extends BaseController{
	
	@Resource
	private MeetingInfoService meetingInfoService;
	
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addMeetingInfo(HttpServletRequest req,MeetingInfo meetingInfo){
		
		System.out.println("m="+meetingInfo);
		int n = meetingInfoService.addMeetingInfo(req, meetingInfo);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteMeetingInfo(HttpServletRequest req,String meeting_id){
		int n = meetingInfoService.deleteMeetingInfo(req, meeting_id);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updateMeetingInfo(HttpServletRequest req,MeetingInfo meetingInfo){
		int n = meetingInfoService.updateMeetingInfo(req, meetingInfo);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findMeetingInfo(HttpServletRequest req,String meeting_id){
		MeetingInfoParam meetingInfo = meetingInfoService.findMeetingInfoById(req, meeting_id);
		return new JsonObjectResult(meetingInfo);
	}
	
	@RequestMapping("/param.do")
	@ResponseBody
	public JsonObjectResult paramMeetingInfo(HttpServletRequest req,FindMeetingInfoParam param){
		System.out.println("con="+param);
		List<MeetingInfoParam> list = meetingInfoService.findMeetingInfoByParam(req, param);
		String count = meetingInfoService.countMeetingInfoByParam(req, param);
		return new JsonObjectResult(count,list);
	}
	
	@ExceptionHandler(MeetingInfoNotFoundException.class)
	@ResponseBody
	public JsonObjectResult meetingInfoException(MeetingInfoNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(1011,e);
	}
}
